package com.ruoyi.wq.service.impl;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.Condition;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.wq.mapper.WqQunMapper;
import com.ruoyi.wq.mapper.WqQunTopicMapper;
import com.ruoyi.wq.domain.WqQun;
import com.ruoyi.wq.domain.WqQunTopic;
import com.ruoyi.wq.domain.vo.WqQunTopicVO;
import com.ruoyi.wq.domain.vo.WqQunVO;
import com.ruoyi.wq.service.IWqQunTopicService;

import cn.hutool.core.date.DateUtil;

/**
 * 群主题Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-08-23
 */
@Service
public class WqQunTopicServiceImpl extends ServiceImpl<WqQunTopicMapper, WqQunTopic> implements IWqQunTopicService {

    @Autowired
    private WqQunTopicMapper wqQunTopicMapper;
    
    @Autowired
    private WqQunMapper wqQunMapper;

    /**
     * 查询群主题
     * 
     * @param id 群主题主键
     * @return 群主题
     */
    @Override
    public WqQunTopic selectWqQunTopicById(String id)
    {
        return wqQunTopicMapper.selectWqQunTopicById(id);
    }

    /**
     * 查询群主题列表
     * 
     * @param wqQunTopic 群主题
     * @return 群主题
     */
    @Override
    public List<WqQunTopic> selectWqQunTopicList(WqQunTopic wqQunTopic)
    {
        return wqQunTopicMapper.selectWqQunTopicList(wqQunTopic);
    }

    /**
     * 新增群主题
     * 
     * @param wqQunTopic 群主题
     * @return 结果
     */
    @Override
    public int insertWqQunTopic(WqQunTopic wqQunTopic)
    {
        wqQunTopic.setCreateTime(DateUtils.getNowDate());
        return wqQunTopicMapper.insertWqQunTopic(wqQunTopic);
    }

    /**
     * 修改群主题
     * 
     * @param wqQunTopic 群主题
     * @return 结果
     */
    @Override
    public int updateWqQunTopic(WqQunTopic wqQunTopic)
    {
        wqQunTopic.setUpdateTime(DateUtils.getNowDate());
        return wqQunTopicMapper.updateWqQunTopic(wqQunTopic);
    }

    /**
     * 批量删除群主题
     * 
     * @param ids 需要删除的群主题主键
     * @return 结果
     */
    @Override
    public int deleteWqQunTopicByIds(String[] ids)
    {
        return wqQunTopicMapper.deleteWqQunTopicByIds(ids);
    }

    /**
     * 删除群主题信息
     * 
     * @param id 群主题主键
     * @return 结果
     */
    @Override
    public int deleteWqQunTopicById(String id)
    {
        return wqQunTopicMapper.deleteWqQunTopicById(id);
    }

	@Override
	public TableDataInfo getPageList(WqQunTopic wqQunTopic) {
		IPage<WqQunTopicVO> page = baseMapper.selectPageList(Condition.getPage(wqQunTopic), wqQunTopic);
		for(WqQunTopicVO vo : page.getRecords()){
			WqQun wqQun = new WqQun();
			wqQun.setQunTopicId(vo.getId());
			IPage<WqQunVO> pageBean = wqQunMapper.selectPageList(Condition.getPage(1, 3), wqQun);
			for(WqQunVO qunVO : pageBean.getRecords()){
				qunVO.setPubDate(DateUtil.formatDate(qunVO.getCreateTime()));
			}
			vo.setQunList(pageBean.getRecords());
		}
		return Condition.getTableDataInfo(page.getRecords(), page.getTotal());
	}

	@Override
	public List<Map<String, String>> getList(WqQunTopic wqQunTopic) {
		return baseMapper.getList();
	}
}
